package Sys_Module;

import java.util.LinkedList;

public class Queue {
    public LinkedList<Integer> list;// 声明队列

    public Queue() {
        list = new LinkedList<Integer>();// 初始化队列
    }

    public void list_put_in(int Num) {// 用于放入队列
        if (Num == 0)
            return;
        list.add(Num);
    }

    public synchronized int list_get_out() {// 用于拿出队列
        if (list.size() <= 0)
            return 0;
        return list.poll();
    }

    public synchronized String list_display() {
        String temp = "";
        if (list.size() <= 0)
            return "";
        for (Integer i : list) {
            temp = temp + String.valueOf(i) + ",";
        }
        return temp.substring(0, temp.length() - 1);
    }

    public synchronized boolean list_restore_data(String data) {
        String[] format_data = data.split(",");
        // int i = 0;
        for (String ii : format_data) {
            list_put_in(Integer.valueOf(ii));
        }
        if (list_get_length() == format_data.length) {
            return true;
        } else {
            return false;
        }
    }

    public int list_get_length() {
        return list.size();
    }

}
